from PySide6.QtWidgets import QApplication
from src.main.vision.windows.login_window import LoginUiLoader
from src.main.vision.windows.main_window import MainUiLoader
from src.main.vision.windows.register_window import RegisterUiLoader


class AppController:
    def __init__(self):
        self.app = QApplication([])
        self.current_window = None

    def show_login(self):
        self._close_current_window()
        self.current_window = LoginUiLoader(self)
        self.current_window.window.show()

    def show_register(self):
        self._close_current_window()
        self.current_window = RegisterUiLoader(self)
        self.current_window.window.show()

    def show_main(self):
        self._close_current_window()
        self.current_window = MainUiLoader(self)
        self.current_window.window.show()
    def _close_current_window(self):
        if self.current_window and self.current_window.window:
            self.current_window.window.close()

    def run(self):
        self.show_login()  # 默认展示登录界面
        # self.show_main()
        self.app.exec()


if __name__ == '__main__':
    try:
        controller = AppController()
        controller.run()
    except Exception as e:
        print(f"报错啦！错误为：{e}")
